package engine.hw;

import engine.util.Timer;

public class RunTimer
{
    
    //<editor-fold defaultstate="collapsed" desc="Singleton">
    private static RunTimer singleton;
    
    public static RunTimer get()
    {
        if (singleton == null)
        {
            singleton = new RunTimer();
        }
        return singleton;
    }
    //</editor-fold>
    
    
    private float frameTime;
    //<editor-fold defaultstate="collapsed" desc="getFrameTime">
    public float getFrameTime()
    {
        return this.frameTime;
    }
    //</editor-fold>
    
    private float runTime;
    //<editor-fold defaultstate="collapsed" desc="getRunTime">
    public float getRunTime()
    {
        return this.runTime;
    }
    //</editor-fold>
    
    private int frame;
    //<editor-fold defaultstate="collapsed" desc="getFrame">
    public int getFrame()
    {
        return this.frame;
    }
    //</editor-fold>
    
    private Timer frameTimer;
    private Timer runTimer;
    
    private RunTimer()
    {
        this.frameTimer = new Timer(false);
        this.runTimer = new Timer(false);
    }
    
    public void initialize()
    {
        this.frameTimer.start();
        this.runTimer.start();
        this.frame = 0;
    }

    public void update()
    {
        this.updateFrameTime();
        this.updateRunTime();
        this.updateFrame();
    }
    
    private void updateFrameTime()
    {
        this.frameTime = this.frameTimer.getTimePassed();
        this.frameTimer.resetAndContinue();
    }
    
    private void updateRunTime()
    {
        this.runTime = this.runTimer.getTimePassed();
    }
    
    private void updateFrame()
    {
        this.frame++;
    }
    
    public void destroy()
    {
        this.frameTimer.destroy();
        this.frameTimer = null;
        this.runTimer.destroy();
        this.runTimer = null;
        this.frame = 0;
    }
    
}
